package cn.wolfcode.shop.cloud.mq;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@RocketMQMessageListener(
        consumerGroup = MQConstans.CREATE_ORDER_SUCCESS_GROUP,
        topic = MQConstans.SECKILL_ORDER_TOPIC,
        selectorExpression = MQConstans.CREATE_ORDER_SUCCESS_TAG
)
public class OrderSuccessMQListener implements RocketMQListener<Map> {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public void onMessage(Map map) {
        System.out.println("订单成功 --- " );
        //构建消息
        MessageBuilder<Map> builder = MessageBuilder.withPayload(map);
        Message<Map> message = builder.build();

        rocketMQTemplate.syncSend(MQConstans.CREATE_ORDER_DELAY_DEST,message,5000,6); //3
    }
}
